#ifndef _DRV_UART_H
#define _DRV_UART_H
#ifdef __cplusplus
 extern "C" {
#endif
#include "main.h"



#define UART_NUM 1

typedef struct uart_gpio
{
	uint16_t pin;
    uint16_t pinaf;
	GPIO_TypeDef *gpio;
}uart_gpio;

typedef struct uart_para_t
{
  uint32_t baudrate;
  uint32_t wordlength;
  uint32_t stopbits;
  uint32_t parity;
  uint32_t mode;
  uint32_t hwflowctl;
  uint32_t oversampling;
  USART_TypeDef *uartx;
} uart_para_t;

typedef struct uart_dma
{
    uint8_t *memoryaddr;
    uint32_t bufsize;
    uint32_t priority;
	uint32_t channel;
	DMA_Stream_TypeDef *dma_stream;
	USART_TypeDef *uartx;
}uart_dma;


#define UART1_CLK_ENABLE()		

#define UART1_TX_PORT           GPIOA
#define UART1_TX_PIN            GPIO_PIN_9
#define UART1_TX_PINAF	 		GPIO_AF7_USART1


#define UART1_RX_PORT      		GPIOA
#define UART1_RX_PIN            GPIO_PIN_10
#define UART1_RX_PINAF	 		GPIO_AF7_USART1

#define	UART1_FIFO_EN	1

#if UART1_FIFO_EN
	#define UART1_BAUD			115200
	#define UART1_TX_BUF_SIZE	1*512
	#define UART1_RX_BUF_SIZE	1*512
#endif

void clock_open(void);
void uart_gpio_cfg(const uart_gpio *pgpio);
void uart_cfg(const uart_para_t *puart);
void tx_dma_cfg(const uart_dma *pdma);
void rx_dma_cfg(const uart_dma *pdma);
void nvic_cfg(void);


#ifdef __cplusplus
}
#endif
#endif /*__ usart_H */
